package cn.edu.lzzy.vm;

import cn.edu.lzzy.entities.Chapter;
import cn.edu.lzzy.entities.Course;
import cn.edu.lzzy.entities.User;
import lombok.Getter;
import lombok.Setter;


import java.util.Date;
import java.util.UUID;

@Getter
@Setter
public class VmCourse {
    private static User user;
    private UUID id;
    private String name;//课程名
    private String description;// 课程说明
    private String cover;//
    private Date createTime;//创建时间
    private Date updateTime;//更新时间
    private boolean isOpen;//开放状态
    private User teacher;//任课教师
    private int type;//获取类型
    private String token;//随机

    private String TeacherAvatar;

    private String TeacherName;

    private int CoverStudents;

    private UUID TeacherId;

    private int CountChapters;

    private int CoverChapter;
    public VmCourse() {
    }

    public VmCourse(Course course){
        id=course.getId();
        name=course.getName();
        description=course.getDescription();
        cover=course.getCover();
        createTime=course.getCreateTime();
        updateTime=course.getUpdateTime();
        isOpen=course.isOpen();
        type = user.getType();
        token=UUID.randomUUID().toString();

    }

    public static VmCourse create(Course course, boolean teacher){
        VmCourse vm = new VmCourse();
        vm.setId(course.getId());
        vm.setName(course.getName());
        vm.setDescription(course.getDescription());
        vm.setCover(course.getCover());
        vm.setCreateTime(course.getCreateTime());
        vm.setUpdateTime(course.getUpdateTime());
        vm.setOpen(course.isOpen());
        vm.setTeacherAvatar(course.getTeacher().getAvatar());
        vm.setTeacherName(course.getTeacher().getNickName());
        vm.setCoverStudents(course.getStudents().size());

        if (teacher){
        vm.setTeacherId(course.getTeacher().getId());
        vm.setCountChapters(course.getChapters().size());
        }else{
           vm.setCoverChapter((int) course.getChapters().stream().filter(Chapter::isOpen).count());
        }
        return vm;
    }
}
